//////////////////////////////////////////////////////////////////////
// PowerThread.h: interface for the CPowerThread class.
//
//Version:
//    1.1.0
//Date:
//    2007.11.15
//////////////////////////////////////////////////////////////////////

#ifndef POWERTHREAD_H
#define POWERTHREAD_H


#include "GUI.h"
#include "Pm.h"
#include "data.h"


//----------------------------------------------------------------

class GUI_API CPowerThread  
{
public:
    BOOL ResumnSign(); //Not support now
    void GetCallbackFunction(void (* *pCallbackFunc)(PowerStatusType powStatus, int iBatteryPercent));
    void SetCallbackFunction(void (*pCallbackFunc)(PowerStatusType powStatus, int iBatteryPercent));
    void StopCapture();
    BOOL StartCapture();
    BOOL GetRunStatus();
    void SetTimeout(ULONG ulTime);
    
    CPowerThread();
    virtual ~CPowerThread();


protected:
    virtual void OnNotifyPower(PowerStatusType powStatus, int iBatteryPercent);
        
    
    //The critical section function
    inline void    InitLock()    { InitializeCriticalSection(&m_csLock); }
    inline void LockThis()    { EnterCriticalSection(&m_csLock);      }    
    inline void    UnLockThis()  { LeaveCriticalSection(&m_csLock);      }
    inline void    DelLock()     { DeleteCriticalSection(&m_csLock);     }


private:
    PowerStatusType GetPowerStatus(PPOWER_BROADCAST pPowerInfo, int *piPercent);
    static DWORD WINAPI PowerThread(PVOID pArg);

    BOOL m_bExitThread;
    ULONG m_ulWaitTime;
    BOOL m_bRunning;
    CRITICAL_SECTION m_csLock;

    //This is for callback function.
    void (*m_pNotifyPower)(PowerStatusType powStatus, int iBatteryPercent);
};
#endif